package Vue;

import org.newdawn.slick.*;

/**
 *
 * @author Ivelios
 */
public class Camera implements IElementGraphique{

    private int posX,posY;
    private int updateCounter;
    private int updateTime;
    private int speed;
    private float zoom;
    private float currentZoom;
    private float speedZoom; // 2 chiffres après la virgule maximum

    public static Camera instance;

    private Camera() {
        this.posX = 0;
        this.posY = 0;
        this.updateCounter = 0;
        this.speed = 1;
        this.updateTime = 10;
        this.zoom = 1.0f;
        this.currentZoom = zoom;
        this.speedZoom = 0.01f;
    }

    public static Camera getInstance(){
        if(instance == null){
            instance = new Camera();
        }
        return instance;
    }

    public int getPosX() {
        return posX;
    }

    public int getPosY() {
        return posY;
    }

    public float getZoom() {
        return currentZoom;
    }

    public void init(GameContainer container) throws SlickException {
    }

    public void render(GameContainer gc, Graphics g) {
        g.drawString(((float)(int)(this.getZoom()*10))/10+"", 10, 30);
    }

    public void update(GameContainer gc, int delta) {
        Input input = gc.getInput();

        this.updateCounter += delta;
        
        if(updateCounter > updateTime){
            //Gestion du zoom
            if(((int)(currentZoom*100)) < ((int)(zoom*100))){
                currentZoom += speedZoom;
            }else if(((int)(currentZoom*100)) > ((int)(zoom*100))){
                currentZoom -= speedZoom;
            }

            //Deplacement de la carte
            updateCounter -= updateTime;

            boolean down = false;
            boolean up = false;
            boolean left = false;
            boolean right = false;
            
            if(input.isKeyDown(Input.KEY_DOWN)){down = true;}
            if(input.isKeyDown(Input.KEY_UP)){up = true;}
            if(input.isKeyDown(Input.KEY_LEFT)){left = true;}
            if(input.isKeyDown(Input.KEY_RIGHT)){right = true;}

            //Déplacement de la carte
            if(down){posY-=speed;}
            if(up){posY+=speed;}
            if(left){posX+=speed;}
            if(right){posX-=speed;}           
        }


    }

    public void mouseWheelMoved(int change) {
		if (change < 0) {
			if(zoom>0.5f){zoom-=0.1f;}
		}
		if (change > 0) {
			if(zoom<2.5f){zoom+=0.1f;}
		}
	}

    


}
